//
//  BRFAQDetailViewController.m
//  BrezzeSaaS
//
//  Created by IOS on 2021/10/8.
//  Copyright © 2021 Brezze GWG. All rights reserved.
//

#import "BRFAQDetailViewController.h"
#import "BROderReportViewController.h"
#import "BRSupportView.h"

@interface BRFAQDetailViewController ()
{
    QMUILabel *_titleL;
    QMUILabel *_subTitleL;
}

@property (nonatomic,strong) BRSupportView *supportView;

@end

@implementation BRFAQDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setUI];
    
    [self br_blockAction];
}

- (void)br_blockAction {
    WS(weakSelf);
    self.navView.rightClickBlock = ^{
        [weakSelf supportClick];
    };
    
    
}

- (void)feedbackClick {
    
    BROderReportViewController *rVC  = [[BROderReportViewController alloc] init];
    rVC.vcType = Report_FAQ;
    rVC.feedbackIn = 1;
    [self.navigationController pushViewController:rVC animated:YES];
}

- (void)supportClick {
    [self.supportView show];
}

- (void)setDto:(BRFAQModel *)dto {
    _dto = dto;
//    _titleL.text = dto.title;
//    _subTitleL.text = dto.content;
//    [_titleL sizeToFit];
//    [_subTitleL sizeToFit];
}

#pragma mark - SET UI --
- (void)setUI {
    
    [self br_createTop:Localized(@"help_helpCentre") imageRStr:@"help_customer"];
    self.navView.popView.hidden = NO;
    
//    CGFloat bottom_h = 82 + kSafeAreaBottomHeight;
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, kSafeAreaTopHeight, kScreenWidth, kScreenHeight - kSafeAreaTopHeight)];
    scrollView.backgroundColor = UIColorClear;
    [self.view addSubview:scrollView];
    
    if (@available(iOS 11.0, *)) {
        scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    
    UIView *contentView = [[UIView alloc] init];
    contentView.backgroundColor = UIColor.clearColor;
    [scrollView addSubview:contentView];
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.offset(0);
        make.width.mas_equalTo(kScreenWidth);
    }];
    
    QMUILabel *titleLabel = [[QMUILabel alloc] init];
    titleLabel.textColor = kColorTitle;
    titleLabel.numberOfLines = 0;
    titleLabel.font = [UIFont fontB:21];
    [contentView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(contentView).offset(36);
        make.left.equalTo(contentView.mas_left).offset(28);
        make.right.equalTo(contentView.mas_right).offset(-28);
    }];
    titleLabel.text = @"--";
    
    QMUILabel *textLB = [[QMUILabel alloc] init];
    textLB.textColor = kColorTitle;
    textLB.numberOfLines = 0;
    textLB.font = [UIFont fontM:14];
    [contentView addSubview:textLB];
    [textLB mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(contentView.mas_left).offset(28);
        make.right.equalTo(contentView.mas_right).offset(-14);
        make.top.equalTo(titleLabel.mas_bottom).offset(28);
        make.bottom.offset(-30);
    }];
    textLB.text = @"--";
    
    _titleL = titleLabel;
    _subTitleL = textLB;
    if (self.dto) {
        titleLabel.text = self.dto.title;
        
        NSMutableAttributedString *att = [[NSMutableAttributedString alloc] initWithString:self.dto.content];
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        paragraphStyle.lineSpacing = 5;

        [att addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, att.length)];

        textLB.attributedText = att;
    }
    
    [self.view addSubview:self.supportView];
}

- (BRSupportView *)supportView {
    
    if (_supportView == nil) {
        _supportView = [[BRSupportView alloc] initWithFrame:self.view.bounds];
    }
    
    return _supportView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
